package br.com.java.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import br.com.java.dao.GenericDAO;
import br.com.java.service.GenericService;

@SuppressWarnings("unchecked")
public class GenericServiceImpl<ENTITY, TYPE, DAO> implements GenericService<ENTITY, TYPE, DAO>{

	/**
	 * 
	 */
	private static final long serialVersionUID = -2823097979604722168L;
	//
	// Dependencies
	//
	protected DAO baseDao;
 
	@Autowired
	public void setBaseDao(DAO baseDao){
		this.baseDao = baseDao;
	}

	@Override
	public void saveOrUpdate(ENTITY object) {
		((GenericDAO<ENTITY, TYPE>)baseDao).saveOrUpdate(object);
		
	}

	@Override
	public void remove(ENTITY object) {
		((GenericDAO<ENTITY, TYPE>)baseDao).remove(object);
	}

	@Override
	public ENTITY retrieveById(Long id) {
		return ((GenericDAO<ENTITY, TYPE>)baseDao).retrieveById(id);
	}

	@Override
	public List<ENTITY> retrieveAll() {
		return ((GenericDAO<ENTITY, TYPE>)baseDao).retrieveAll();
	}

	

	/*
	//
	// Implementation
	//	
	@Transactional
	public void save(ENTITY entity) {
		((GenericDAO<ENTITY, TYPE>)baseDao).save(entity);
	}

	@Transactional
	public void merge(ENTITY entity) {
		((GenericDAO<ENTITY, TYPE>)baseDao).merge(entity);
	}

	@Transactional
	public void remove(ENTITY entity) {
		((GenericDAO<ENTITY, TYPE>)baseDao).remove(entity);
	}

	@Transactional
	public void removeById(TYPE id) {
		((GenericDAO<ENTITY, TYPE>)baseDao).removeById(id);
	}

	@Transactional
	public ENTITY getById(TYPE id) {
		return ((GenericDAO<ENTITY, TYPE>)baseDao).getById(id);
	}

	@Transactional
	public Collection<ENTITY> findAll() {
		return ((GenericDAO<ENTITY, TYPE>)baseDao).findAll();
	}

	@Transactional
	public Query createQuery(String query, Object... parameters) {
		return ((GenericDAO<ENTITY, TYPE>)baseDao).createQuery(query, parameters);
	}
	*/
}
